//
//  DeviceMsgCell.m
//  efairy
//
//  Created by 李锋 on 2019/7/3.
//  Copyright © 2019年 East. All rights reserved.
//

#import "DeviceMsgCell.h"

@implementation DeviceMsgCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}






- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self initView];
    }
    return self;
}


-(void)initView{
    _checkedImage = [[UIImageView alloc]init];
    _checkedImage.image = [UIImage imageNamed:@"icon_no_checked"];
    
    _mContentView = [[UIView alloc]init];
    _mContentView.backgroundColor = [UIColor whiteColor];
    _mContentView.layer.cornerRadius = 3;
    
    
    _portraitImgView = [[UIImageView alloc]init];
    _portraitImgView.image = [UIImage imageNamed:@"msg_device_icon"];
    
    _redPointView = [[UIView alloc]init];
    _redPointView.backgroundColor = [UIColor redColor];
    
    _nameLabel = [[UILabel alloc]init];
    _nameLabel.font = [UIFont boldSystemFontOfSize:15.f];
    _nameLabel.textColor = ColorFromRGB(0x333333);
    
    
    _timeLabel = [[UILabel alloc]init];
    _timeLabel.font = [UIFont systemFontOfSize:11.f];
    _timeLabel.textColor = ColorFromRGB(0x666666);
    _timeLabel.textAlignment = NSTextAlignmentRight;
    
    
    _msgLabel = [[UILabel alloc]init];
    _msgLabel.font = [UIFont boldSystemFontOfSize:13.f];
    _msgLabel.textColor = ColorFromRGB(0x666666);
    
    [_mContentView sd_addSubviews:@[_portraitImgView,_redPointView,_nameLabel,_timeLabel,_msgLabel]];
    
    _portraitImgView.sd_layout.heightIs(34).widthIs(34).leftSpaceToView(_mContentView, 12).topSpaceToView(_mContentView, 15);
    _redPointView.sd_layout.heightIs(8).heightIs(8).leftSpaceToView(_mContentView, 42).topSpaceToView(_mContentView, 15);
    _nameLabel.sd_layout.widthIs(133).heightIs(15).leftSpaceToView(_portraitImgView, 12).topSpaceToView(_mContentView, 12);
    _timeLabel.sd_layout.heightIs(11).leftSpaceToView(_nameLabel, 10).rightSpaceToView(_mContentView, 12).topSpaceToView(_mContentView, 14);
    _msgLabel.sd_layout.heightIs(13).leftSpaceToView(_portraitImgView, 12).rightSpaceToView(_mContentView, 12).topSpaceToView(_nameLabel, 12);
    
    
    [self.contentView sd_addSubviews:@[_checkedImage,_mContentView]];
    _checkedImage.sd_layout.widthIs(20).heightIs(20).leftSpaceToView(self.contentView, 9).topSpaceToView(self.contentView, 22);
    _mContentView.sd_layout.heightIs(64).leftSpaceToView(_checkedImage, 9).rightSpaceToView(self.contentView, 8);
    
    [self setupAutoHeightWithBottomView:_mContentView bottomMargin:0];
    
    
}




- (void)configViewWithRCConversation:(EFAMsgIMItem *)item {
    if(item != nil){
        _msgLabel.text = item.efairymsg_content;
        //        NSLog(@"cell消息内容%@,id=%@",item.efairymsg_content,item.msgId);
        _nameLabel.text = item.efairydevice_name;
        _timeLabel.text = item.efairymsg_add_time;
        if(item.isRead == 0){
            _redPointView.hidden = NO;
        }else{
            _redPointView.hidden = YES;
        }
    }
    
    
    
}

@end
